package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TFormConfig;
import com.ruoyi.system.service.ITFormConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 表单配置Controller
 * 
 * @author xwj
 * @date 2024-03-30
 */
@RestController
@RequestMapping("/system/form")
public class TFormConfigController extends BaseController
{
    @Autowired
    private ITFormConfigService tFormConfigService;

    /**
     * 查询表单配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TFormConfig tFormConfig)
    {
        startPage();
        List<TFormConfig> list = tFormConfigService.selectTFormConfigList(tFormConfig);
        return getDataTable(list);
    }

    /**
     * 导出表单配置列表
     */
    @Log(title = "表单配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TFormConfig tFormConfig)
    {
        List<TFormConfig> list = tFormConfigService.selectTFormConfigList(tFormConfig);
        ExcelUtil<TFormConfig> util = new ExcelUtil<TFormConfig>(TFormConfig.class);
        util.exportExcel(response, list, "表单配置数据");
    }

    /**
     * 获取表单配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tFormConfigService.selectTFormConfigById(id));
    }

    @GetMapping(value = "/info")
    public AjaxResult getInfo(String tableName)
    {
        return success(tFormConfigService.getByTable(tableName));
    }

    /**
     * 新增表单配置
     */
    @Log(title = "表单配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TFormConfig tFormConfig)
    {
        return success(tFormConfigService.insertTFormConfig(tFormConfig, getLoginUser()));
    }

    /**
     * 修改表单配置
     */
    @Log(title = "表单配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TFormConfig tFormConfig)
    {
        return toAjax(tFormConfigService.updateTFormConfig(tFormConfig));
    }

    /**
     * 删除表单配置
     */
    @Log(title = "表单配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tFormConfigService.deleteTFormConfigByIds(ids));
    }
}
